home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / examples / chap06 / ValueInJava.java < prev    next >
Text File  |  1996-09-29  |  989b  |  37 lines

  1. //
  2. // parameters are inside Java codes.
  3. //
  4.  
  5. import vrml.*;
  6. import vrml.node.*;
  7. import vrml.field.*;
  8.  
  9. public class ValueInJava extends Script{
  10.     SFVec3f set_translation;
  11.     float currentPosition[] = new float[3];
  12.     float offset[] = new float[3];
  13.  
  14.     public void initialize(){
  15.         // get the reference of the event out 'set_translation'.
  16.         set_translation = (SFVec3f)getEventOut("set_translation");
  17.  
  18.         // initialize currentPosition and offset.
  19.         currentPosition[0] = 0.0f;
  20.         currentPosition[1] = 0.0f;
  21.         currentPosition[2] = 0.0f;
  22.         offset[0] = 1.0f;
  23.         offset[1] = 0.0f;
  24.         offset[2] = 0.0f;
  25.     }
  26.  
  27.     public void processEvent(Event e){
  28.         if(e.getName().equals("touched") == true){
  29.             currentPosition[0] += offset[0];
  30.             currentPosition[1] += offset[1];
  31.             currentPosition[2] += offset[2];
  32.             set_translation.setValue(currentPosition);
  33.         }
  34.     }
  35. }
  36.  
  37.